package com.hkts.beltweigher.master.controller;


import com.alibaba.fastjson.JSON;

import java.text.ParseException;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hkts.beltweigher.master.vo.PageVo;
import com.hkts.beltweigher.utils.CustomPageUtils;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.GetMapping;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.hkts.beltweigher.utils.Result;
import com.hkts.beltweigher.utils.ResultUtil;
import com.hkts.beltweigher.master.service.IYbHourAccumulateService;
import com.hkts.beltweigher.master.entity.YbHourAccumulate;

/**
 * @author hml
 * @since 2024-04-10
 */
@RestController
@RequestMapping("/order/ybHourAccumulate")
public class YbHourAccumulateController {
    private final Logger logger = LoggerFactory.getLogger(YbHourAccumulateController.class);

    @Autowired
    public IYbHourAccumulateService iYbHourAccumulateService;

    /**
     * 分页查询数据
     *
     * @param page             分页信息
     * @param ybHourAccumulate 查询条件
     * @return
     */
    @ResponseBody
    @GetMapping("/getYbHourAccumulatePageList")
    public Result<Object> getHontUserList(Page<YbHourAccumulate> page, YbHourAccumulate ybHourAccumulate) {
        return ResultUtil.data(CustomPageUtils.getCustomPage(iYbHourAccumulateService.selectPage(page, ybHourAccumulate)));
    }

    /**
     * 保存和修改公用的
     *
     * @param ybHourAccumulate 传递的实体
     * @return saveOrUpdate
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/ybHourAccumulateSave")
    public Result<Object> ybHourAccumulateSave(YbHourAccumulate ybHourAccumulate) {
        iYbHourAccumulateService.saveOrUpdate(ybHourAccumulate);
        return ResultUtil.success("保存成功");
    }

    /**
     * 根据id获取对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/ybHourAccumulateGetById")
    public Result<Object> ybHourAccumulateGetById(String id) {
        YbHourAccumulate byId = iYbHourAccumulateService.getById(id);
        return ResultUtil.data(byId);
    }

    /**
     * 根据id删除对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/ybHourAccumulateDelete")
    public Result<Object> hontUserDelete(String id) {
        iYbHourAccumulateService.removeById(id);
        return ResultUtil.success("删除成功");
    }

    /**
     * 批量删除对象
     *
     * @param item 实体集合ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/ybHourAccumulateBatchDelete")
    public Result<Object> deleteBatchIds(String item) {
        List<String> ids = (List<String>) JSON.parse(item);
        iYbHourAccumulateService.removeByIds(ids);
        return ResultUtil.success("删除成功");
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/getChart")
    public Result<Object> getChart(PageVo vo) throws ParseException {
        Map<String, Object> aChar = iYbHourAccumulateService.getChar(vo);
        return ResultUtil.data(aChar);
    }

}
